package com.example.neusoft.yuejian.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian.Base.BaseActivity;
import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;
import com.example.neusoft.yuejian.Bean.ActDetailBean;
import com.example.neusoft.yuejian.Bean.GuanzhuBean;
import com.example.neusoft.yuejian.Bean.MatchBean;
import com.example.neusoft.yuejian.Bean.MatchDetailBean;
import com.example.neusoft.yuejian.Bean.MgzBean;
import com.example.neusoft.yuejian.Fragment.ShouyeFragment;
import com.example.neusoft.yuejian.R;
import com.squareup.picasso.Picasso;

import retrofit2.Call;

public class MatchDetailActivity extends BaseActivity implements View.OnClickListener {
    private MatchDetailBean match;
    private TextView bsdz,bsjj,bsmc,bssj;
    private Button bsbm;
    private ImageView bstp,match_fh,gz;
    private SharedPreferences sp1 ;
    private int id,uid;

    @Override
    public int getLayoutFile() {
        return R.layout.match_detail;
    }

    @Override
    public void initView() {
         bsdz=(TextView)findViewById(R.id.bsdz);
         bsjj=(TextView)findViewById(R.id.bsjj);
         bsmc=(TextView)findViewById(R.id.bsmc);
         bssj=(TextView)findViewById(R.id.bssj);
         bsbm=(Button)findViewById(R.id.bsbm);
         bstp=(ImageView)findViewById(R.id.bstp);
         match_fh=(ImageView)findViewById(R.id.match_fh);
         gz=(ImageView)findViewById(R.id.gz);

    }

    @Override
    public void initEvent() {
       bsbm.setOnClickListener(this);
       match_fh.setOnClickListener(this);
       gz.setOnClickListener(this);
    }

    @Override
    public void initData() {
        Intent intent=getIntent();
        int id=intent.getIntExtra("mid",0);
        sp1=MatchDetailActivity.this.getSharedPreferences("User", MatchDetailActivity.this.MODE_PRIVATE);
        uid= sp1.getInt("id",0);
        getmatchdetail(id,uid);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bsbm:
                Intent intent = new Intent(this, MatchEnrollActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("mid", match);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.match_fh:
                finish();
                break;
            case R.id.gz:
                getmgz(id,uid);
                break;
        }
    }
    private void getmatchdetail(int id,int uid){
        BaseModel<MatchDetailBean>model=new BaseModel<>();
        Call<MatchDetailBean>call=model.service.macthdetail(id,uid);
        model.callEnqueue(call,list);
    }

    BaseListener<MatchDetailBean> list=new BaseListener<MatchDetailBean>() {
        @Override
        public void onResponse(MatchDetailBean matchDetailBean) {
            match=matchDetailBean;
            bsmc.setText(match.getMname());
            bsjj.setText(match.getMintro());
            bssj.setText(match.getMstarttime());
            bsdz.setText(match.getMaddress());
            id=match.getMid();
            Picasso.with(MatchDetailActivity.this).load("http://10.0.2.2/YueJian/public/static/img/" +
                    match.getMpic()).into(bstp);
//            if (matchDetailBean.getFlag()==1){
//                gz.setImageResource(R.drawable.ic_xin1);
//            }else {
//                gz.setImageResource(R.drawable.ic_gz);
//            }
        }

        @Override
        public void onFail(String msg) {
            showToast("获取最近比赛详情失败");
        }
    };
    private void getmgz(int id,int uid){
        BaseModel<MgzBean> model=new BaseModel<>();
        Call<MgzBean> call=model.service.getmgz( id, uid);
        model.callEnqueue(call,list1);
    }
    BaseListener<MgzBean> list1=new BaseListener<MgzBean>() {
        @Override
        public void onResponse(MgzBean mgzBean) {
            if(mgzBean.getStatus()==1){
                gz.setImageResource(R.drawable.ic_xin1);
                showToast(mgzBean.getMessage());

            }else{
                showToast(mgzBean.getMessage());

            }
        }

        @Override
        public void onFail(String msg) {
            showToast("111");
        }
    };
}

